<template>
  <div>
    <!--  搜索栏  -->
    <div style="margin-bottom: 20px;margin-top: 20px">
      <el-input v-model="searchName" placeholder="请输入商品名"
                suffix-icon="el-icon-search" style="width: 200px;"
                @keyup.enter.native="loadPost"></el-input>

      <el-select style="margin-left: 15px" v-model="storage" placeholder="请选择仓库">
        <el-option
            v-for="(item,index) in storageData"
            :key="item.id"
            :label="item.name"
            :value="item.id">
        </el-option>
      </el-select>

      <el-select style="margin-left: 15px" v-model="goodstype" placeholder="请选择分类">
        <el-option
            v-for="item in goodstypeData"
            :key="item.id"
            :label="item.name"
            :value="item.id">
        </el-option>
      </el-select>

      <el-button type="primary" style="margin-left: 10px" @click="loadPost">查询</el-button>
      <el-button type="success" style="margin-left: 10px" @click="resetParam">重置</el-button>
    </div>

    <!--  表格  -->
    <el-table :data="tableData" stripe border
              :header-cell-style="{background:'#f3f6fd',color:'#555','text-align':'center'}"
              :cell-style="{'text-align':'center'}" style="width: 100%"
    >
      <el-table-column prop="id" label="ID" width="50">
      </el-table-column>
      <el-table-column prop="goodsname" label="商品名" width="200">
      </el-table-column>
      <el-table-column prop="storagename" label="所属仓库" width="150" >
      </el-table-column>
      <el-table-column prop="goodstypename" label="商品分类" width="150" >
      </el-table-column>
      <el-table-column prop="adminname" label="操作人" width="120">
      </el-table-column>
      <el-table-column prop="username" label="申请人" width="120">
      </el-table-column>
      <el-table-column prop="count" label="数量" width="100">
      </el-table-column>
      <el-table-column prop="createtime" label="操作时间" width="200">
      </el-table-column>
      <el-table-column prop="remark" label="备注"  width=“auto” min-width=“10%”>
      </el-table-column>
    </el-table>
    <!--  分页  -->
    <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageNum"
        :page-sizes="[ 5, 10, 20, 40]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
    </el-pagination>

  </div>
</template>

<script>
export default {
  name: "RecordMange",
  data() {
    return {
      user:JSON.parse(sessionStorage.getItem("CurUser")),
      goodstypeData:[],
      storageData:[],
      tableData: [],
      pageSize: 10,
      pageNum: 1,
      total: 0,
      storage:'',
      goodstype:'',
      searchName: '',
      centerDialogVisible: false,
      roleId:'',
      userId:''
    }
  },
  methods: {
    //分页查询数据
    loadPost() {
      this.$axios.post(this.$httpUrl + '/record/listPage', {
        pageSize: this.pageSize,
        pageNum: this.pageNum,
        param: {
          name: this.searchName,
          goodstype: this.goodstype+'',
          storage: this.storage+'',
          roleId: this.user.roleId+'',
          userId:this.user.id+''
        }
      }).then(res => {
        console.log(res)
        if (res.data.code == 200) {
          this.tableData = res.data.data;
          this.total = res.data.total
        } else {
          alert('获取数据失败')
        }
      })
    },
    loadStorage() {
      this.$axios.get(this.$httpUrl + '/storage/list').then(res=>res.data).then(res => {
        if (res.code == 200) {
          this.storageData = res.data;
        } else {
          alert('获取数据失败')
        }
      })
    },
    loadGoodsType() {
      this.$axios.get(this.$httpUrl + '/goodstype/list').then(res=>res.data).then(res => {
        if (res.code == 200) {
          this.goodstypeData = res.data;
        } else {
          alert('获取数据失败')
        }
      })
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.pageNum = 1
      this.pageSize = val
      this.loadPost()
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.pageNum = val
      this.loadPost()
    },
    resetParam() {
      this.searchName = '';
      this.storage=''
      this.goodstype=''
    },
  },
  beforeMount() {
    this.loadStorage();
    this.loadGoodsType();
    this.loadPost();
  }
}
</script>

<style scoped>


</style>